{% extends "base_generic.html" %}

{% block title %}All Borrowed Books - Admin - Local Library{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
  <div>
    <h1><i class="bi bi-tools"></i> All Borrowed Books</h1>
    <p class="text-muted">Manage all library borrowing records</p>
  </div>
</div>

{% if borrowrecord_list %}
  <div class="table-responsive">
    <table class="table table-striped table-hover">
      <thead class="table-dark">
        <tr>
          <th>Book</th>
          <th>Author</th>
          <th>Borrower</th>
          <th>Borrowed Date</th>
          <th>Due Date</th>
          <th>Status</th>
          <th>Actions</th>
        </tr>
      </thead>
      <tbody>
        {% for record in borrowrecord_list %}
          <tr {% if record.is_overdue %}class="table-danger"{% endif %}>
            <td>
              <a href="{{ record.book_instance.book.get_absolute_url }}" class="text-decoration-none">
                {{ record.book_instance.book.title }}
              </a>
              <br>
              <small class="text-muted">ID: {{ record.book_instance.id|slice:":8" }}...</small>
            </td>
            <td>{{ record.book_instance.book.author }}</td>
            <td>
              <strong>{{ record.user.get_full_name|default:record.user.username }}</strong>
              <br>
              <small class="text-muted">{{ record.user.email }}</small>
            </td>
            <td>{{ record.borrow_date|date:"M j, Y" }}</td>
            <td>
              {{ record.due_date }}
              {% if record.is_overdue %}
                <br><span class="badge bg-danger">Overdue</span>
              {% endif %}
            </td>
            <td>
              {% if record.status == 'borrowed' %}
                {% if record.is_overdue %}
                  <span class="badge bg-danger">Overdue</span>
                {% else %}
                  <span class="badge bg-success">Active</span>
                {% endif %}
              {% elif record.status == 'returned' %}
                <span class="badge bg-secondary">Returned</span>
              {% endif %}
            </td>
            <td>
              {% if record.status != 'returned' %}
                <a href="{% url 'admin-return-book' record.id %}" class="btn btn-success btn-sm">
                  <i class="bi bi-arrow-return-left"></i> Return
                </a>
              {% else %}
                <span class="text-muted">—</span>
              {% endif %}
            </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
{% else %}
  <div class="text-center py-5">
    <i class="bi bi-bookmark display-1 text-muted"></i>
    <h3 class="mt-3">No borrowed books</h3>
    <p class="text-muted">No books are currently borrowed from the library.</p>
  </div>
{% endif %}

{% endblock %} 